<template>
	<view class="home">
		<view class="asdtop"
			style="display: flex;align-items: flex-end;justify-content: center;width: 750rpx;height: 100rpx;">
			<button @click="chushihua" class="mini-btn" style="margin: 0 10rpx;" type="primary"
				size="mini">获取设备编码</button>
			<view class="" style="margin-left: 50rpx;font-size: 40rpx;">
				设备编码：{{sheb}}
			</view>

		</view>
		<view class="abr">
			<view class="abr-l">

				<view class="hometop">
					测站参数修改：{{fif}}
				</view>

				<view class="abr-r">
					<button class="mini-btn" @click="abritembb(item)" :disabled="disabled" type="primary" size="mini"
						v-for="(item,index) in buttnum" :key="index">{{item.name}}</button>
				</view>
				<view class="abrlist">
					<view class="abritem">
						<view class="abrtext">
							测站序号：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linea" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							底宽：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineb" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							左坡角度：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linec" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							右坡角度：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lined" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							水位修正：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linee" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							左坡系数：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linef" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							右坡系数：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineg" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							经度：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineh" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							纬度：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linei" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							左线系数：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linej" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							右线系数：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linek" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							流量系数：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linel" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线数量：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linem" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标1：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linen" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标2：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineo" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标3：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linep" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标4：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineq" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标5：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="liner" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标6：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lines" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标7：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linet" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标8：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineu" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标9：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linev" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标10：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linew" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							测线坐标11：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linex" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数1：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="liney" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数2：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linez" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数3：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineaa" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数4：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineab" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数5：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineac" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数6：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="linead" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数7：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineae" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数8：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineaf" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数9：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineag" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数10：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineah" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abritem">
						<view class="abrtext">
							系数11：
						</view>
						<view class="abrinput">
							<uni-easyinput v-model="lineai" type="digit" :styles="styles"
								:placeholderStyle="placeholderStyle" placeholder="请输入内容"></uni-easyinput>
						</view>
					</view>
					<view class="abrcheckbox">
						<uni-data-checkbox v-model="radio1" :localdata="nub1"></uni-data-checkbox>
						<uni-data-checkbox v-model="radio2" :localdata="nub2"></uni-data-checkbox>
					</view>

				</view>
			</view>
		</view>
		<view class="bott">
			<button @click="chushihua" class="mini-btn" style="margin: 0 10rpx;" type="primary"
				size="mini">获取设备编码</button>
			<!-- <button @click="writenubaa" class="mini-btn" style="margin: 0 10rpx;" type="primary"
				size="mini">获取测站信息</button> -->
			<!-- <button @click="writeBLECharacteristicValue" style="margin: 0 10rpx;" class="mini-btn" type="primary" size="mini">获取设备信息</button> -->
			<button @click="inpuaa" class="mini-btn" style="margin: 0 10rpx;" type="primary" size="mini">修改信息</button>
			<!-- <button @click="duankai" class="mini-btn" style="margin: 0 10rpx;" type="primary" size="mini">断开蓝牙</button> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				placeholderStyle: "color:#c1c1c1;font-size:14px",
				disabled: false,
				linea: '',
				lineb: '',
				linec: '',
				lined: '',
				linee: '',
				linef: '',
				lineg: '',
				lineh: '',
				linei: '',
				linej: '',
				linek: '',
				linel: '',
				linem: '',
				linen: '',
				lineo: '',
				linep: '',
				lineq: '',
				liner: '',
				lines: '',
				linet: '',
				lineu: '',
				linev: '',
				linew: '',
				linex: '',
				liney: '',
				linez: '',
				lineaa: '',
				lineab: '',
				lineac: '',
				linead: '',
				lineae: '',
				lineaf: '',
				lineag: '',
				lineah: '',
				lineai: '',
				lineag: '',
				lineah: '',
				lineai: '',
				lineaj: '',
				radio1: 0,
				radio2: 0,

				xxlinea: '0000',
				xxlineb: '0000',
				xxlinec: '0000',
				xxlined: '0000',
				xxlinee: '0000',
				xxlinef: '0000',
				xxlineg: '0000',
				xxlineh: '0000',
				xxlinei: '0000',
				xxlinej: '0000',
				xxlinek: '0000',
				xxlinel: '0000',
				xxlinem: '0000',
				xxlinen: '0000',
				xxlineo: '0000',
				xxlinep: '0000',
				xxlineq: '0000',
				xxliner: '0000',
				xxlines: '0000',
				xxlinet: '0000',
				xxlineu: '0000',
				xxlinev: '0000',
				xxlinew: '0000',
				xxlinex: '0000',
				xxliney: '0000',
				xxlinez: '0000',
				xxlineaa: '0000',
				xxlineab: '0000',
				xxlineac: '0000',
				xxlinead: '0000',
				xxlineae: '0000',
				xxlineaf: '0000',
				xxlineag: '0000',
				xxlineah: '0000',
				xxlineai: '0000',
				xxlineag: '0000',
				xxlineah: '0000',
				xxlineai: '0000',
				xxlineaj: '0000',
				xxradio1: 0,
				xxradio2: 0,
				nub1: [{
						text: '一点法',
						value: 1
					},
					{
						text: '三点法',
						value: 3
					},
				],

				nub2: [{
						text: '测站',
						value: 67
					},
					{
						text: '计量点',
						value: 74
					},
				],
				vuexlist: {},
				abriteminfo: '',
				infoaa: true,
				infobb: true,
				fanti: true,
				modifynum: '00',
				nubsfg: '',
				buttnum: [{
						id: '00',
						nub: '30',
						name: '#1'
					},
					{
						id: '28',
						nub: '30',
						name: '#2'
					},
					{
						id: '50',
						nub: '30',
						name: '#3'
					},
					{
						id: '78',
						nub: '30',
						name: '#4'
					},
					{
						id: 'a0',
						nub: '30',
						name: '#5'
					},
					{
						id: 'c8',
						nub: '30',
						name: '#6'
					},
					{
						id: 'f0',
						nub: '30',
						name: '#7'
					},
					{
						id: '18',
						nub: '31',
						name: '#8'
					},
					{
						id: '40',
						nub: '31',
						name: '#9'
					},
				],
				fif: '',
				styles: {
					color: '#999999',
					borderColor: '#c3c3c3'
				},
				num: 50,
				lists: [],
				list: [],
				deviceId: '',
				serviceId: '',
				characteristics: [],
				characteristicId: '',
				iceinfo: false,
				resHexitem: '',
				// msgall: []
				msgall: ['', '0x03', '0x30', '0x00', '0x00', '0x28', '', ''],
				jis: '',
				cr: '',
				fff: '',
				abrnum: '00',
				sheb: '',
				countcrca: '',
				countcrcb: '',
				countcrcc: '',
				countcrcd: '',
				countcrce: '',
				countcrcf: '',
				countall: [],
				cezhan: ['1', '10', '3', '4', '00', '28', '50', ],
			}
		},
		onLoad(options) {
			this.deviceId = this.vuex_deviceId
			this.getBLEDeviceServices()
			uni.showLoading({
				title: '开启服务中...'
			});
			setTimeout(() => {
				uni.hideLoading()
			}, 10000)
		},
		onShow() {

		},
		destroyed() {
			console.log('销毁');
		},
		methods: {
			//获取蓝牙的所有服务
			getBLEDeviceServices() {
				console.log('所有服务');
				setTimeout(() => {
					uni.getBLEDeviceServices({
						// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
						deviceId: this.deviceId,
						success: (res) => {
							console.log('蓝牙服务', res);
							//E95D93AF-251D-470A-A062-FA1922DFA9A8
							//6E400001-B5A3-F393-E0A9-E50E24DCCA9E
							res.services.forEach((item) => {

								if (item.uuid.indexOf("0000FFF0") != -1) {
									this.serviceId = item.uuid;
									console.log("UUid", this.serviceId)
									//获取特征
									this.getBLEDeviceCharacteristics()
								}
								if (item.uuid.indexOf("0000FFE0") != -1) {
									this.serviceId = item.uuid;
									console.log("UUid", this.serviceId)
									//获取特征
									this.getBLEDeviceCharacteristics()
								}
							})
						}
					})
				}, 1000)
			},
			//获取蓝牙特征
			getBLEDeviceCharacteristics() {
				console.log("进入特征");
				setTimeout(() => {
					uni.getBLEDeviceCharacteristics({
						// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
						deviceId: this.deviceId,
						// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
						serviceId: this.serviceId,
						success: (res) => {
							console.log('特征', res.characteristics)
							this.characteristics = res.characteristics
							res.characteristics.forEach((item) => {

								if (item.uuid.indexOf("FFF2") != -1) {
									this.fff = item.uuid
									console.log('ff1', this.fff);
								}
								if (item.uuid.indexOf("FFE1") != -1) {
									this.fff = item.uuid
									console.log('ff2', this.fff);
								}
								if (item.uuid.indexOf("0000FFE1") != -1) {
									console.log('item特征', item);
									this.characteristicId = item.uuid
									console.log('特征值Id', this.characteristicId);
									//console.log('characteristicId:', item.uuid)
									//利用传参的形势传给下面的notify，这里的uuid如果都需要用到，就不用做判断了，建议使用setTimeout进行间隔性的调用此方法
									this.notifyBLECharacteristicValueChange(item.uuid)
								}
								if (item.uuid.indexOf("0000FFF1") != -1) {
									console.log('item特征', item);
									this.characteristicId = item.uuid
									console.log('特征值Id', this.characteristicId);
									//console.log('characteristicId:', item.uuid)
									//利用传参的形势传给下面的notify，这里的uuid如果都需要用到，就不用做判断了，建议使用setTimeout进行间隔性的调用此方法
									this.notifyBLECharacteristicValueChange(item.uuid)
								}
							})
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}, 1000)
			},
			// 启用 notify 功能
			notifyBLECharacteristicValueChange(characteristicId) {
				console.log('设备ID', this.deviceId);
				console.log('服务ID', this.serviceId);
				console.log('特征ID', this.characteristicId);
				uni.notifyBLECharacteristicValueChange({
					state: true, // 启用 notify 功能
					// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
					deviceId: this.deviceId,

					// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
					serviceId: this.serviceId,
					// 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
					characteristicId: this.characteristicId,
					success: (res) => {
						console.log(res)
						// console.log(this.characteristicId)
						console.log('启用功能success', res.errMsg)
						// vuex

						uni.hideLoading()
						this.listenValueChange()
						uni.showToast({
							title: '服务已开启',
							icon: 'success',
							mask: true,
							duration: 1000
						});

					},
					fail: (res) => {
						console.log('启用功能fail', res)
						uni.showToast({
							title: '获取服务失败',
							icon: 'fail',
							mask: true,
							duration: 2000
						});

					}
				})

			},
			// 【9】监听消息变化
			listenValueChange() {
				uni.onBLECharacteristicValueChange(res => {
					console.log('RES', res)
					let resHex = this.ab2hex(res.value)
					let device = resHex[8] + resHex[9]
					console.log('监听初始化数据', resHex);
					this.infoaa = false
					console.log('数据长度', resHex.length);
					if (resHex.length == 14) {
						this.listenValueinfo(device)
						this.infoaa = false
					}
					if (resHex.length == 170) {

						this.gaininfo(resHex)
						this.infoaa = false
					}
					// let slicest = resHex.slice(0, 4)
					// let modifysty = resHex.slice(2, 4)
					// console.log('转换字符', modifysty);

				})
			},
			// 初始化信息处理
			listenValueinfo(resHex) {
				this.resHexitem = resHex
				this.sheb = parseInt(resHex, 16)
				uni.showToast({
					title: '获取信息成功',
					icon: 'success',
					mask: true,
					duration: 2000
				});
				console.log('设备编码', this.resHexitem);
			},
			// 获取信息处理
			gaininfo(resHex) {
				uni.showToast({
					title: '获取信息成功',
					icon: 'success',
					mask: true,
					duration: 2000
				});
				this.infobb = false
				console.log('获取数据', resHex);

				// 测站编号
				let numa = resHex[6] + resHex[7] + resHex[8] + resHex[9] + resHex[10] + resHex[11] + resHex[12] + resHex[
					13]
				let fixeda = parseInt(numa, 16)
				this.linea = fixeda
				// this.fif = fixeda
				console.log('测站编号', numa);

				// 渠道底宽
				let numb = resHex[42] + resHex[43] + resHex[44] + resHex[45]
				let fixedb = parseInt(numb, 16) / 1000
				this.lineb = fixedb
				console.log('渠道底宽', numb);

				// 左坡角度
				let numc = resHex[46] + resHex[47] + resHex[48] + resHex[49]
				let fixedc = parseInt(numc, 16) / 100
				this.linec = fixedc
				console.log('左坡角度', numc);

				// 右坡角度
				let numd = resHex[50] + resHex[51] + resHex[52] + resHex[53]
				let fixedd = parseInt(numd, 16) / 100
				this.lined = fixedd
				console.log('左坡角度', numd);

				// 水位修正
				let nume = resHex[30] + resHex[30] + resHex[32] + resHex[33]
				let fixede = parseInt(nume, 16) / 1000
				this.linee = fixede
				console.log('水位修正', nume);

				// 左坡系数
				let numf = resHex[34] + resHex[35] + resHex[36] + resHex[37]
				let fixedf = parseInt(numf, 16) / 10000
				this.linef = fixedf
				console.log('左坡系数', numf);

				// 右坡系数
				let numg = resHex[38] + resHex[39] + resHex[40] + resHex[41]
				let fixedg = parseInt(numg, 16) / 10000
				this.lineg = fixedg
				console.log('右坡系数', numg);

				// 测站工作模式
				let radioa = resHex[54] + resHex[55]
				let radiob = parseInt(radioa, 16)
				this.radio1 = radiob * 1
				console.log('点法', radioa, this.radio1);

				// 测线数量
				let numm = resHex[56] + resHex[57]
				let fixedm = parseInt(numm, 16)
				this.linem = fixedm
				console.log('测线数量', numm);

				// 经度
				let numh = resHex[14] + resHex[15] + resHex[16] + resHex[17] + resHex[18] + resHex[19] + resHex[20] +
					resHex[21]
				let fixedh = parseInt(numh, 16) / 1000000
				this.lineh = fixedh
				console.log('经度', numh);

				// 纬度
				let numi = resHex[22] + resHex[23] + resHex[24] + resHex[25] + resHex[26] + resHex[27] + resHex[28] +
					resHex[29]
				let fixedi = parseInt(numi, 16) / 1000000
				this.linei = fixedi
				console.log('纬度', numi);

				// 左线系数
				let numj = resHex[146] + resHex[147] + resHex[148] + resHex[149]
				let fixedj = parseInt(numj, 16) / 10000
				this.linej = fixedj
				console.log('左线系数', numj);

				// 右线系数
				let numk = resHex[150] + resHex[151] + resHex[152] + resHex[153]
				let fixedk = parseInt(numk, 16) / 10000
				this.linek = fixedk
				console.log('右线系数', numk);

				// 流量系数
				let numl = resHex[154] + resHex[155] + resHex[156] + resHex[157]
				let fixedl = parseInt(numl, 16) / 10000
				this.linel = fixedl
				console.log('流量系数', numl);

				// 测线坐标1
				let numn = resHex[58] + resHex[59] + resHex[60] + resHex[61]
				let fixedn = parseInt(numn, 16) / 1000
				this.linen = fixedn
				console.log('测线坐标1', numn);

				// 测线坐标2
				let numo = resHex[62] + resHex[63] + resHex[64] + resHex[65]
				let fixedo = parseInt(numo, 16) / 1000
				this.lineo = fixedo
				console.log('测线坐标2', numo);

				// 测线坐标3
				let nump = resHex[66] + resHex[67] + resHex[68] + resHex[69]
				let fixedp = parseInt(nump, 16) / 1000
				this.linep = fixedp
				console.log('测线坐标3', nump);

				// 测线坐标4
				let numq = resHex[70] + resHex[71] + resHex[72] + resHex[73]
				let fixedq = parseInt(numq, 16) / 1000
				this.lineq = fixedq
				console.log('测线坐标4', numq);

				// 测线坐标5
				let numr = resHex[74] + resHex[75] + resHex[76] + resHex[77]
				let fixedr = parseInt(numr, 16) / 1000
				this.liner = fixedr
				console.log('测线坐标5', numr);

				// 测线坐标6
				let nums = resHex[78] + resHex[79] + resHex[80] + resHex[81]
				let fixeds = parseInt(nums, 16) / 1000
				this.lines = fixeds
				console.log('测线坐标6', nums);

				// 测线坐标7
				let numt = resHex[82] + resHex[83] + resHex[84] + resHex[85]
				let fixedt = parseInt(numt, 16) / 1000
				this.linet = fixedt
				console.log('测线坐标7', numt);

				// 测线坐标8
				let numu = resHex[86] + resHex[87] + resHex[88] + resHex[89]
				let fixedu = parseInt(numu, 16) / 1000
				this.lineu = fixedu
				console.log('测线坐标8', numu);

				// 测线坐标9
				let numv = resHex[90] + resHex[91] + resHex[92] + resHex[93]
				let fixedv = parseInt(numv, 16) / 1000
				this.linev = fixedv
				console.log('测线坐标9', numv);

				// 测线坐标10
				let numw = resHex[94] + resHex[95] + resHex[96] + resHex[97]
				let fixedw = parseInt(numw, 16) / 1000
				this.linew = fixedw
				console.log('测线坐标10', numw);

				// 测线坐标11
				let numx = resHex[98] + resHex[99] + resHex[100] + resHex[101]
				let fixedx = parseInt(numx, 16) / 1000
				this.linex = fixedx
				console.log('测线坐标11', numx);

				// 流速系数1
				let numy = resHex[102] + resHex[103] + resHex[104] + resHex[105]
				let fixedy = parseInt(numy, 16) / 10000
				this.liney = fixedy
				console.log('流速系数1', numy);

				// 流速系数2
				let numz = resHex[106] + resHex[107] + resHex[108] + resHex[109]
				let fixedz = parseInt(numz, 16) / 10000
				this.linez = fixedz
				console.log('流速系数2', numz);

				// 流速系数3
				let numaa = resHex[110] + resHex[111] + resHex[112] + resHex[113]
				let fixedaa = parseInt(numaa, 16) / 10000
				this.lineaa = fixedaa
				console.log('流速系数3', numaa);

				// 流速系数4
				let numab = resHex[114] + resHex[115] + resHex[116] + resHex[117]
				let fixedab = parseInt(numab, 16) / 10000
				this.lineab = fixedab
				console.log('流速系数4', numab);

				// 流速系数5
				let numac = resHex[118] + resHex[119] + resHex[120] + resHex[121]
				let fixedac = parseInt(numac, 16) / 10000
				this.lineac = fixedac
				console.log('流速系数5', numac);

				// 流速系数6
				let numad = resHex[122] + resHex[123] + resHex[124] + resHex[125]
				let fixedad = parseInt(numad, 16) / 10000
				this.linead = fixedad
				console.log('流速系数6', numad);

				// 流速系数7
				let numae = resHex[126] + resHex[127] + resHex[128] + resHex[129]
				let fixedae = parseInt(numae, 16) / 10000
				this.lineae = fixedae
				console.log('流速系数7', numae);

				// 流速系数8
				let numaf = resHex[130] + resHex[131] + resHex[132] + resHex[133]
				let fixedaf = parseInt(numaf, 16) / 10000
				this.lineaf = fixedaf
				console.log('流速系数8', numaf);

				// 流速系数9
				let numag = resHex[134] + resHex[135] + resHex[136] + resHex[137]
				let fixedag = parseInt(numag, 16) / 10000
				this.lineag = fixedag
				console.log('流速系数9', numag);

				// 流速系数10
				let numah = resHex[138] + resHex[139] + resHex[140] + resHex[141]
				let fixedah = parseInt(numah, 16) / 10000
				this.lineah = fixedah
				console.log('流速系数10', numah);

				// 流速系数11
				let numai = resHex[142] + resHex[143] + resHex[144] + resHex[145]
				let fixedai = parseInt(numai, 16) / 10000
				this.lineai = fixedai
				console.log('流速系数11', numai);

				// 测站类型
				let numaj = resHex[158] + resHex[159]
				let fixedaj = parseInt(numaj, 16)
				this.radio2 = fixedaj
				console.log('测站类型', numaj);
			},
			// ArrayBuffer转16进度字符串示例
			ab2hex(buffer) {
				const hexArr = Array.prototype.map.call(
					new Uint8Array(buffer),
					function(bit) {
						return ('00' + bit.toString(16)).slice(-2)
					}
				)
				return hexArr.join('')
			},
			// crc校验
			crc16up(data) {
				var res = this.crc16(Buffer.from(data, "hex"));
				this.cr = res
			},
			crc16(data) {
				let crcValue = 0xFFFF;
				for (let i = 0; i < data.length; i++) {
					crcValue ^= data[i] & 0xFFFF
					for (let j = 0; j < 8; j++) {
						if (crcValue & 0x0001) {
							crcValue >>= 1
							crcValue ^= 0xA001
						} else {
							crcValue >>= 1
						}
					}
				}

	let crcstr = crcValue.toString(16).toUpperCase();
								if(crcstr.length % 2 == 0){
									let crcArr = crcstr.match(/.{1,2}/g)
									console.log('CRC16验证',crcArr);
									
									let arr = new Array(2)
									arr[0] = crcArr[1]
									arr[1] = crcArr[0]
									return arr
									// return result;
								}else{
									let str = '0' + crcstr
									let crcArr = str.match(/.{1,2}/g)
									console.log('CRC16验证',crcArr);
									let arr = new Array(2)
									arr[0] = crcArr[1]
									arr[1] = crcArr[0]
									return arr
								}
				// crcValue = crcValue.toString(16)
				// let crcArr = new Array(2)
				// crcArr[0] = crcValue.substring(2, 4)
				// crcArr[1] = crcValue.substring(0, 2)
				// return crcArr
			},
			// #1-#9
			abritembb(item) {
				this.linea = ''
				this.lineb = ''
				this.linec = ''
				this.lined = ''
				this.linee = ''
				this.linef = ''
				this.lineg = ''
				this.lineh = ''
				this.linei = ''
				this.linej = ''
				this.linek = ''
				this.linel = ''
				this.linem = ''
				this.linen = ''
				this.lineo = ''
				this.linep = ''
				this.lineq = ''
				this.liner = ''
				this.lines = ''
				this.linet = ''
				this.lineu = ''
				this.linev = ''
				this.linew = ''
				this.linex = ''
				this.liney = ''
				this.linez = ''
				this.lineaa = ''
				this.lineab = ''
				this.lineac = ''
				this.linead = ''
				this.lineae = ''
				this.lineaf = ''
				this.lineag = ''
				this.lineah = ''
				this.lineai = ''
				this.lineag = ''
				this.lineah = ''
				this.lineai = ''
				this.lineaj = ''
				this.radio1 = 0,
					this.radio2 = 0,
					this.abritem(item)
				this.disabled = true
				setTimeout(() => {
					this.disabled = false
					console.log('停止循环');
					if (this.infobb) {
						this.infobb = false
						uni.hideLoading()
						uni.showToast({
							title: '获取失败',
							icon: 'fail',
							mask: true,
							duration: 2000
						});

						return
					}
				}, 5000)
			},
			abritem(item) {
				uni.showLoading({
					title: '获取中',
					mask: true
				});
				this.infobb = true
				this.abriteminfo = item
				this.modifynum = item.id
				this.nubsfg = item.nub
				this.countera = ''
				this.counterb = ''
				this.counterr = ''
				// this.abrnum = id
				// this.msgall.length = 0
				this.fif = item.name
				console.log('id', item);
				this.writeBLECharacteristicValue(item)
			},
			//读取蓝牙
			writeBLECharacteristicValue(id) {
				let iditem = id.id
				let bssdfg = id.nub
				// let msgall = ['','0x03','0x10','0x00','0x00','0x06','','']
				// let msgall = ['0x0c', '0x03', '0x30', '0x00', '0x00', '0x28', '0x4b', '0xc9']
				this.jis = this.resHexitem + '03' + bssdfg + iditem + '00' + '28'
				console.log('计算初始', this.jis);
				this.crc16up(this.jis)
				this.msgall[0] = '0x' + this.resHexitem
				this.msgall[6] = '0x' + this.cr[0]
				this.msgall[7] = '0x' + this.cr[1]
				this.msgall[2] = '0x' + bssdfg
				this.msgall[3] = '0x' + iditem
				// msg = [0x22,0x03,0x10,0x00,0x00,0x06,0xc6,0x5b]
				// let msg = JSON.parse( msgall )
				// console.log('json',msg);
				setTimeout(() => {
					if (this.msgall[0] !== '') {
						const buffer = new ArrayBuffer(8)
						const dataView = new DataView(buffer)
						for (var i = 0; i < this.msgall.length; i++) {
							dataView.setUint8(i, this.msgall[i])
						}

						uni.writeBLECharacteristicValue({
							deviceId: this.deviceId,
							serviceId: this.serviceId,
							// characteristicId: '0000FFF2-0000-1000-8000-00805F9B34FB',
							characteristicId: this.fff,
							value: buffer,
							success: (res) => {
								console.log('读取发送成功', res, this.msgall)
								setTimeout(() => {
									console.log('循环');
									if (this.infobb) {
										this.abritem(this.abriteminfo)
									}
								}, 500)
							},
							fail: (res) => {
								if (res.errCode == 10006) {
									uni.hideLoading()
									uni.showToast({
										title: '当前连接已断开',
										icon: 'success',
										mask: true,
										duration: 2000
									});
								}
								if (res.errCode == 10004) {
									uni.hideLoading()
									uni.showToast({
										title: '未找到服务',
										icon: 'success',
										mask: true,
										duration: 2000
									});
								}
								if (res.errCode == 10005) {
									uni.hideLoading()
									uni.showToast({
										title: '未找到特征值',
										icon: 'success',
										mask: true,
										duration: 2000
									});
								}
								console.log('111', JSON.stringify(res))
								console.log('222', JSON.stringify(buffer))
							}
						})
					}
				}, 500)

			},
			// 初始化设备ID
			writenubaa() {
				this.writenub()
				setTimeout(() => {
					console.log('停止循环');
					if (this.infoaa) {
						this.infoaa = false
						uni.hideLoading()
						uni.showToast({
							title: '获取失败',
							icon: 'fail',
							mask: true,
							duration: 2000
						});
						return
					}
				}, 10000)
			},
			writenub() {
				uni.showLoading({
					title: '获取中',
					mask: true
				});
				this.infoaa = true

				let msg = ['0x0c', '0x03', '0x30', '0x00', '0x00', '0x28', '0x4b', '0xc9']
				// msg = [0x22,0x03,0x10,0x00,0x00,0x06,0xc6,0x5b]
				// let msg = JSON.parse( msgall )
				// console.log('json',msg);
				console.log('this.fff', this.fff);
				const buffer = new ArrayBuffer(8)
				const dataView = new DataView(buffer)
				// dataView.setUint8(0, 0)

				// dataView.setUint8(0, msg[0]);
				// dataView.setUint8(1, msg[1]);
				// dataView.setUint8(2, msg[2]);
				// dataView.setUint8(3, msg[3]);
				// dataView.setUint8(4, msg[4]);
				// dataView.setUint8(5, msg[5]);
				// dataView.setUint8(6, msg[6]);
				// dataView.setUint8(7, msg[7]);

				for (var i = 0; i < msg.length; i++) {
					dataView.setUint8(i, msg[i]);
				}

				uni.writeBLECharacteristicValue({
					deviceId: this.deviceId,
					serviceId: this.serviceId,
					// characteristicId: '0000FFE1-0000-1000-8000-00805F9B34FB',
					characteristicId: this.fff,
					value: buffer,
					success: (res) => {
						console.log('写入', res)
						// setTimeout(() => {
						// 	console.log('循环');
						// 	if (this.infoaa) {
						// 		this.writenub()
						// 	}
						// }, 500)
					},
					fail: (res) => {
						if (res.errCode == 10006) {
							uni.hideLoading()
							uni.showToast({
								title: '当前连接已断开',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						if (res.errCode == 10004) {
							uni.hideLoading()
							uni.showToast({
								title: '未找到服务',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						if (res.errCode == 10005) {
							uni.hideLoading()
							uni.showToast({
								title: '未找到特征值',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						console.log(JSON.stringify(res))
						console.log(JSON.stringify(buffer))
					}
				})
			}, // 初始化设备ID
			chushihua() {
				this.chushih()
				setTimeout(() => {
					console.log('停止循环');
					if (this.infoaa) {
						this.infoaa = false
						uni.hideLoading()
						uni.showToast({
							title: '获取失败',
							icon: 'fail',
							mask: true,
							duration: 2000
						});
						return
					}
				}, 10000)
			},
			chushih() {
				uni.showLoading({
					title: '获取中',
					mask: true
				});
				this.infoaa = true

				let msg = ['0x00', '0x03', '0xff', '0x02', '0x00', '0x01', '0x14', '0x0f']
				// msg = [0x22,0x03,0x10,0x00,0x00,0x06,0xc6,0x5b]
				// let msg = JSON.parse( msgall )
				// console.log('json',msg);
				console.log('this.fff', this.fff);
				const buffer = new ArrayBuffer(8)
				const dataView = new DataView(buffer)

				for (var i = 0; i < msg.length; i++) {
					dataView.setUint8(i, msg[i]);
					// dataView.setUint8(i, msg.charAt(i).charCodeAt())
				}

				uni.writeBLECharacteristicValue({
					deviceId: this.deviceId,
					serviceId: this.serviceId,
					// characteristicId: '0000FFE1-0000-1000-8000-00805F9B34FB',
					characteristicId: this.fff,
					value: buffer,
					success: (res) => {
						console.log('写入', res)
						setTimeout(() => {
							console.log('循环');
							if (this.infoaa) {
								this.chushih()
							}
						}, 500)
					},
					fail: (res) => {
						if (res.errCode == 10006) {
							uni.hideLoading()
							uni.showToast({
								title: '当前连接已断开',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						if (res.errCode == 10004) {
							uni.hideLoading()
							uni.showToast({
								title: '未找到服务',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						if (res.errCode == 10005) {
							uni.hideLoading()
							uni.showToast({
								title: '未找到特征值',
								icon: 'success',
								mask: true,
								duration: 2000
							});
						}
						console.log(JSON.stringify(res))
						console.log(JSON.stringify(buffer))
					}
				})
			},
			duankai() {
				uni.closeBLEConnection({
					deviceId: this.deviceId,
					success(res) {
						console.log(res)
						uni.showToast({
							title: '蓝牙已断开',
							icon: 'success',
							mask: true,
							duration: 2000
						});
					}
				})
			},
			inpuaa() {
				// this.fanti = true
				// setTimeout(() => {
				// 	console.log('停止循环');
				// 	if (this.fanti) {
				// 		this.fanti = false
				// 		uni.hideLoading()
				// 		uni.showToast({
				// 			title: '修改失败',
				// 			icon: 'fail',
				// 			mask: true,
				// 			duration: 2000
				// 		});
				// 		return
				// 	}
				// }, 10000)
				this.modifyup()

			},
			// 修改蓝牙
			modifyup() {

				// uni.showLoading({
				// 	title: '修改中',
				// 	mask: true
				// });
				let iditem = this.modifynum
this.countall.length = 0
				// 修改测站编号
				let laa = this.linea * 1
				let liaa = laa.toFixed(0) * 1
				let straa = liaa.toString(16).split('')
				if (straa.length == 1) {
					this.xxlinea = '0' + '0' + '0' + straa[0]
				}
				if (straa.length == 2) {
					this.xxlinea = '0' + '0' + straa[0] + straa[1]
				}
				if (straa.length == 3) {
					this.xxlinea = '0' + straa[0] + straa[1] + straa[2]
				}
				if (straa.length == 4) {
					this.xxlinea = straa[0] + straa[1] + straa[2] + straa[3]
				}

				// 修改测站经度
				let lah = this.lineh * 1000000
				let liah = lah.toFixed(0) * 1
				let strah = liah.toString(16).split('')

				if (strah.length == 1) {
					this.xxlineh = '0' + '0' + '0' + '0' + '0' + '0' + '0' + strah[0]
				}
				if (strah.length == 2) {
					this.xxlineh = '0' + '0' + '0' + '0' + '0' + '0' + strah[0] + strah[1]
				}
				if (strah.length == 3) {
					this.xxlineh = '0' + '0' + '0' + '0' + '0' + strah[0] + strah[1] + strah[2]
				}
				if (strah.length == 4) {
					this.xxlineh = '0' + '0' + '0' + '0' + strah[0] + strah[1] + strah[2] + strah[3]
				}
				if (strah.length == 5) {
					this.xxlineh = '0' + '0' + '0' + strah[0] + strah[1] + strah[2] + strah[3] + strah[4]
				}
				if (strah.length == 6) {
					this.xxlineh = '0' + '0' + strah[0] + strah[1] + strah[2] + strah[3] + strah[4] + strah[5]
				}
				if (strah.length == 7) {
					this.xxlineh = '0' + strah[0] + strah[1] + strah[2] + strah[3] + strah[4] + strah[5] + strah[6]
				}
				if (strah.length == 8) {
					this.xxlineh = strah[0]
				}
				console.log('经度转换', this.xxlineh);

				// 修改测站纬度
				let lai = this.linei * 1000000
				let liai = lai.toFixed(0) * 1
				let strai = liai.toString(16).split('')

				if (strai.length == 1) {
					this.xxlinei = '0' + '0' + '0' + '0' + '0' + '0' + '0' + strai[0]
				}
				if (strai.length == 2) {
					this.xxlinei = '0' + '0' + '0' + '0' + '0' + '0' + strai[0] + strai[1]
				}
				if (strai.length == 3) {
					this.xxlinei = '0' + '0' + '0' + '0' + '0' + strai[0] + strai[1] + strai[2]
				}
				if (strai.length == 4) {
					this.xxlinei = '0' + '0' + '0' + '0' + strai[0] + strai[1] + strai[2] + strai[3]
				}
				if (strai.length == 5) {
					this.xxlinei = '0' + '0' + '0' + strai[0] + strai[1] + strai[2] + strai[3] + strai[4]
				}
				if (strai.length == 6) {
					this.xxlinei = '0' + '0' + strai[0] + strai[1] + strai[2] + strai[3] + strai[4] + strai[5]
				}
				if (strai.length == 7) {
					this.xxlinei = '0' + strai[0] + strai[1] + strai[2] + strai[3] + strai[4] + strai[5] + strai[6]
				}
				if (strai.length == 8) {
					this.xxlinei = strai[0]
				}
				console.log('纬度转换', this.xxlinei);

				// 修改水位基准
				let lae = this.linee * 1000
				let liae = lae.toFixed(0) * 1
				let strae = liae.toString(16).split('')
				if (strae.length == 1) {
					this.xxlinee = '0' + '0' + '0' + strae[0]
				}
				if (strae.length == 2) {
					this.xxlinee = '0' + '0' + strae[0] + strae[1]
				}
				if (strae.length == 3) {
					this.xxlinee = '0' + strae[0] + strae[1] + strae[2]
				}
				if (strae.length == 4) {
					this.xxlinee = strae[0] + strae[1] + strae[2] + strae[3]
				}
				console.log('水位基准转换', this.xxlinee);

				// 修改左坡系数
				let laf = this.linef * 10000
				let liaf = laf.toFixed(0) * 1
				let straf = liaf.toString(16).split('')
				if (straf.length == 1) {
					this.xxlinef = '0' + '0' + '0' + straf[0]
				}
				if (straf.length == 2) {
					this.xxlinef = '0' + '0' + straf[0] + straf[1]
				}
				if (straf.length == 3) {
					this.xxlinef = '0' + straf[0] + straf[1] + straf[2]
				}
				if (straf.length == 4) {
					this.xxlinef = straf[0] + straf[1] + straf[2] + straf[3]
				}
				console.log('左坡系数转换', this.xxlinef);

				// 修改右坡系数
				let lag = this.lineg * 10000
				let liag = lag.toFixed(0) * 1
				let strag = liag.toString(16).split('')
				if (strag.length == 1) {
					this.xxlineg = '0' + '0' + '0' + strag[0]
				}
				if (strag.length == 2) {
					this.xxlineg = '0' + '0' + strag[0] + strag[1]
				}
				if (strag.length == 3) {
					this.xxlineg = '0' + strag[0] + strag[1] + strag[2]
				}
				if (strag.length == 4) {
					this.xxlineg = strag[0] + strag[1] + strag[2] + strag[3]
				}
				console.log('右坡系数转换', this.xxlineg);

				// 修改渠道底宽
				let lab = this.lineb * 1000
				let liab = lab.toFixed(0) * 1
				let strab = liab.toString(16).split('')
				if (strab.length == 1) {
					this.xxlineb = '0' + '0' + '0' + strab[0]
				}
				if (strab.length == 2) {
					this.xxlineb = '0' + '0' + strab[0] + strab[1]
				}
				if (strab.length == 3) {
					this.xxlineb = '0' + strab[0] + strab[1] + strab[2]
				}
				if (strab.length == 4) {
					this.xxlineb = strab[0] + strab[1] + strab[2] + strab[3]
				}
				console.log('渠道底宽转换', this.xxlineb);

				// 修改左坡角度
				let lac = this.linec * 100
				let liac = lac.toFixed(0) * 1
				let strac = liac.toString(16).split('')
				if (strac.length == 1) {
					this.xxlinec = '0' + '0' + '0' + strac[0]
				}
				if (strac.length == 2) {
					this.xxlinec = '0' + '0' + strac[0] + strac[1]
				}
				if (strac.length == 3) {
					this.xxlinec = '0' + strac[0] + strac[1] + strac[2]
				}
				if (strac.length == 4) {
					this.xxlinec = strac[0] + strac[1] + strac[2] + strac[3]
				}
				console.log('左坡角度转换', this.xxlinec);

				// 修改右坡角度
				let lad = this.lined * 100
				let liad = lad.toFixed(0) * 1
				let strad = liad.toString(16).split('')
				if (strad.length == 1) {
					this.xxlined = '0' + '0' + '0' + strad[0]
				}
				if (strad.length == 2) {
					this.xxlined = '0' + '0' + strad[0] + strad[1]
				}
				if (strad.length == 3) {
					this.xxlined = '0' + strad[0] + strad[1] + strad[2]
				}
				if (strad.length == 4) {
					this.xxlined = strad[0] + strad[1] + strad[2] + strad[3]
				}
				console.log('右坡角度转换', this.xxlined);

				// 修改工作模式
				let laradio1 = this.radio1
				let liaradio1 = laradio1.toFixed(0) * 1
				let straradio1 = liaradio1.toString(16).split('')
				if (straradio1.length == 1) {
					this.xxlineradio1 = '0' + straradio1[0]
				}
				if (straradio1.length == 2) {
					this.xxlineradio1 = straradio1[0] + straradio1[1]
				}
				console.log('工作模式转换', this.xxlineradio1);

				// 修改测线数量
				let larm = this.linem * 1
				let liam = larm.toFixed(0) * 1
				let stram = liam.toString(16).split('')
				if (stram.length == 1) {
					this.xxlinem = '0' + stram[0]
				}
				if (stram.length == 2) {
					this.xxlinem = stram[0] + stram[1]
				}
				console.log('测线数量转换', this.xxlinem);

				// 修改坐标1
				let lan = this.linen * 1000
				let lian = lan.toFixed(0) * 1
				let stran = lian.toString(16).split('')
				if (stran.length == 1) {
					this.xxlinen = '0' + '0' + '0' + stran[0]
				}
				if (stran.length == 2) {
					this.xxlinen = '0' + '0' + stran[0] + stran[1]
				}
				if (stran.length == 3) {
					this.xxlinen = '0' + stran[0] + stran[1] + stran[2]
				}
				if (stran.length == 4) {
					this.xxlinen = stran[0] + stran[1] + stran[2] + stran[3]
				}
				console.log('坐标1转换', this.xxlinen);

				// 修改坐标2
				let lao = this.lineo * 1000
				let liao = lao.toFixed(0) * 1
				let strao = liao.toString(16).split('')
				if (strao.length == 1) {
					this.xxlineo = '0' + '0' + '0' + strao[0]
				}
				if (strao.length == 2) {
					this.xxlineo = '0' + '0' + strao[0] + strao[1]
				}
				if (strao.length == 3) {
					this.xxlineo = '0' + strao[0] + strao[1] + strao[2]
				}
				if (strao.length == 4) {
					this.xxlineo = strao[0] + strao[1] + strao[2] + strao[3]
				}
				console.log('坐标2转换', this.xxlineo);

				// 修改坐标3
				let lap = this.linep * 1000
				let liap = lap.toFixed(0) * 1
				let strap = liap.toString(16).split('')
				if (strap.length == 1) {
					this.xxlinep = '0' + '0' + '0' + strap[0]
				}
				if (strap.length == 2) {
					this.xxlinep = '0' + '0' + strap[0] + strap[1]
				}
				if (strap.length == 3) {
					this.xxlinep = '0' + strap[0] + strap[1] + strap[2]
				}
				if (strap.length == 4) {
					this.xxlinep = strap[0] + strap[1] + strap[2] + strap[3]
				}
				console.log('坐标3转换', this.xxlinep);

				// 修改坐标4
				let laq = this.lineq * 1000
				let liaq = laq.toFixed(0) * 1
				let straq = liaq.toString(16).split('')
				if (straq.length == 1) {
					this.xxlineq = '0' + '0' + '0' + straq[0]
				}
				if (straq.length == 2) {
					this.xxlineq = '0' + '0' + straq[0] + straq[1]
				}
				if (straq.length == 3) {
					this.xxlineq = '0' + straq[0] + straq[1] + straq[2]
				}
				if (straq.length == 4) {
					this.xxlineq = straq[0] + straq[1] + straq[2] + straq[3]
				}
				console.log('坐标4转换', this.xxlineq);

				// 修改坐标5
				let lar = this.liner * 1000
				let liar = lar.toFixed(0) * 1
				let strar = liar.toString(16).split('')
				if (strar.length == 1) {
					this.xxliner = '0' + '0' + '0' + strar[0]
				}
				if (strar.length == 2) {
					this.xxliner = '0' + '0' + strar[0] + strar[1]
				}
				if (strar.length == 3) {
					this.xxliner = '0' + strar[0] + strar[1] + strar[2]
				}
				if (strar.length == 4) {
					this.xxliner = strar[0] + strar[1] + strar[2] + strar[3]
				}
				console.log('坐标5转换', this.xxliner);

				// 修改坐标6
				let las = this.lines * 1000
				let lias = las.toFixed(0) * 1
				let stras = lias.toString(16).split('')
				if (stras.length == 1) {
					this.xxlines = '0' + '0' + '0' + stras[0]
				}
				if (stras.length == 2) {
					this.xxlines = '0' + '0' + stras[0] + stras[1]
				}
				if (stras.length == 3) {
					this.xxlines = '0' + stras[0] + stras[1] + stras[2]
				}
				if (stras.length == 4) {
					this.xxlines = stras[0] + stras[1] + stras[2] + stras[3]
				}
				console.log('坐标6转换', this.xxlines);

				// 修改坐标7
				let lat = this.linet * 1000
				let liat = lat.toFixed(0) * 1
				let strat = liat.toString(16).split('')
				if (strat.length == 1) {
					this.xxlinet = '0' + '0' + '0' + strat[0]
				}
				if (strat.length == 2) {
					this.xxlinet = '0' + '0' + strat[0] + strat[1]
				}
				if (strat.length == 3) {
					this.xxlinet = '0' + strat[0] + strat[1] + strat[2]
				}
				if (strat.length == 4) {
					this.xxlinet = strat[0] + strat[1] + strat[2] + strat[3]
				}
				console.log('坐标7转换', this.xxlinet);

				// 修改坐标8
				let lau = this.lineu * 1000
				let liau = lau.toFixed(0) * 1
				let strau = liau.toString(16).split('')
				if (strau.length == 1) {
					this.xxlineu = '0' + '0' + '0' + strau[0]
				}
				if (strau.length == 2) {
					this.xxlineu = '0' + '0' + strau[0] + strau[1]
				}
				if (strau.length == 3) {
					this.xxlineu = '0' + strau[0] + strau[1] + strau[2]
				}
				if (strau.length == 4) {
					this.xxlineu = strau[0] + strau[1] + strau[2] + strau[3]
				}
				console.log('坐标8转换', this.xxlineu);

				// 修改坐标9
				let lav = this.linev * 1000
				let liav = lav.toFixed(0) * 1
				let strav = liav.toString(16).split('')
				if (strav.length == 1) {
					this.xxlinev = '0' + '0' + '0' + strav[0]
				}
				if (strav.length == 2) {
					this.xxlinev = '0' + '0' + strav[0] + strav[1]
				}
				if (strav.length == 3) {
					this.xxlinev = '0' + strav[0] + strav[1] + strav[2]
				}
				if (strav.length == 4) {
					this.xxlinev = strav[0] + strav[1] + strav[2] + strav[3]
				}
				console.log('坐标9转换', this.xxlinev);

				// 修改坐标10
				let law = this.linew * 1000
				let liaw = law.toFixed(0) * 1
				let straw = liaw.toString(16).split('')
				if (straw.length == 1) {
					this.xxlinew = '0' + '0' + '0' + straw[0]
				}
				if (straw.length == 2) {
					this.xxlinew = '0' + '0' + straw[0] + straw[1]
				}
				if (straw.length == 3) {
					this.xxlinew = '0' + straw[0] + straw[1] + straw[2]
				}
				if (straw.length == 4) {
					this.xxlinew = straw[0] + straw[1] + straw[2] + straw[3]
				}
				console.log('坐标10转换', this.xxlinew);

				// 修改坐标11
				let lax = this.linex * 1000
				let liax = law.toFixed(0) * 1
				let strax = liax.toString(16).split('')
				if (strax.length == 1) {
					this.xxlinex = '0' + '0' + '0' + strax[0]
				}
				if (strax.length == 2) {
					this.xxlinex = '0' + '0' + strax[0] + strax[1]
				}
				if (strax.length == 3) {
					this.xxlinex = '0' + strax[0] + strax[1] + strax[2]
				}
				if (strax.length == 4) {
					this.xxlinex = strax[0] + strax[1] + strax[2] + strax[3]
				}
				console.log('坐标11转换', this.xxlinex);

				// 修改流速系数1
				let lay = this.liney * 10000
				let liay = lay.toFixed(0) * 1
				let stray = liay.toString(16).split('')
				if (stray.length == 1) {
					this.xxliney = '0' + '0' + '0' + stray[0]
				}
				if (stray.length == 2) {
					this.xxliney = '0' + '0' + stray[0] + stray[1]
				}
				if (stray.length == 3) {
					this.xxliney = '0' + stray[0] + stray[1] + stray[2]
				}
				if (stray.length == 4) {
					this.xxliney = stray[0] + stray[1] + stray[2] + stray[3]
				}
				console.log('流速系数1转换', this.xxliney);

				// 修改流速系数2
				let laz = this.linez * 10000
				let liaz = laz.toFixed(0) * 1
				let straz = liaz.toString(16).split('')
				if (straz.length == 1) {
					this.xxlinez = '0' + '0' + '0' + straz[0]
				}
				if (straz.length == 2) {
					this.xxlinez = '0' + '0' + straz[0] + straz[1]
				}
				if (straz.length == 3) {
					this.xxlinez = '0' + straz[0] + straz[1] + straz[2]
				}
				if (straz.length == 4) {
					this.xxlinez = straz[0] + straz[1] + straz[2] + straz[3]
				}
				console.log('流速系数2转换', this.xxlinez);

				// 修改流速系数3
				let laaa = this.lineaa * 10000
				let liaaa = laaa.toFixed(0) * 1
				let straaa = liaaa.toString(16).split('')
				if (straaa.length == 1) {
					this.xxlineaa = '0' + '0' + '0' + straaa[0]
				}
				if (straaa.length == 2) {
					this.xxlineaa = '0' + '0' + straaa[0] + straaa[1]
				}
				if (straaa.length == 3) {
					this.xxlineaa = '0' + straaa[0] + straaa[1] + straaa[2]
				}
				if (straaa.length == 4) {
					this.xxlineaa = straaa[0] + straaa[1] + straaa[2] + straaa[3]
				}
				console.log('流速系数3转换', this.xxlineaa);

				// 修改流速系数4
				let laab = this.lineab * 10000
				let liaab = laab.toFixed(0) * 1
				let straab = liaab.toString(16).split('')
				if (straab.length == 1) {
					this.xxlineab = '0' + '0' + '0' + straab[0]
				}
				if (straab.length == 2) {
					this.xxlineab = '0' + '0' + straab[0] + straab[1]
				}
				if (straab.length == 3) {
					this.xxlineab = '0' + straab[0] + straab[1] + straab[2]
				}
				if (straab.length == 4) {
					this.xxlineab = straab[0] + straab[1] + straab[2] + straab[3]
				}
				console.log('流速系数4转换', this.xxlineab);

				// 修改流速系数5
				let laac = this.lineac * 10000
				let liaac = laac.toFixed(0) * 1
				let straac = liaac.toString(16).split('')
				if (straac.length == 1) {
					this.xxlineac = '0' + '0' + '0' + straac[0]
				}
				if (straac.length == 2) {
					this.xxlineac = '0' + '0' + straac[0] + straac[1]
				}
				if (straac.length == 3) {
					this.xxlineac = '0' + straac[0] + straac[1] + straac[2]
				}
				if (straac.length == 4) {
					this.xxlineac = straac[0] + straac[1] + straac[2] + straac[3]
				}
				console.log('流速系数5转换', this.xxlineac);

				// 修改流速系数6
				let laad = this.linead * 10000
				let liaad = laad.toFixed(0) * 1
				let straad = liaad.toString(16).split('')
				if (straad.length == 1) {
					this.xxlinead = '0' + '0' + '0' + straad[0]
				}
				if (straad.length == 2) {
					this.xxlinead = '0' + '0' + straad[0] + straad[1]
				}
				if (straad.length == 3) {
					this.xxlinead = '0' + straad[0] + straad[1] + straad[2]
				}
				if (straad.length == 4) {
					this.xxlinead = straad[0] + straad[1] + straad[2] + straad[3]
				}
				console.log('流速系数6转换', this.xxlinead);

				// 修改流速系数7
				let laae = this.lineae * 10000
				let liaae = laae.toFixed(0) * 1
				let straae = liaae.toString(16).split('')
				if (straae.length == 1) {
					this.xxlineae = '0' + '0' + '0' + straae[0]
				}
				if (straae.length == 2) {
					this.xxlineae = '0' + '0' + straae[0] + straae[1]
				}
				if (straae.length == 3) {
					this.xxlineae = '0' + straae[0] + straae[1] + straae[2]
				}
				if (straae.length == 4) {
					this.xxlineae = straae[0] + straae[1] + straae[2] + straae[3]
				}
				console.log('流速系数7转换', this.xxlineae);

				// 修改流速系数8
				let laaf = this.lineaf * 10000
				let liaaf = laaf.toFixed(0) * 1
				let straaf = liaaf.toString(16).split('')
				if (straaf.length == 1) {
					this.xxlineaf = '0' + '0' + '0' + straaf[0]
				}
				if (straaf.length == 2) {
					this.xxlineaf = '0' + '0' + straaf[0] + straaf[1]
				}
				if (straaf.length == 3) {
					this.xxlineaf = '0' + straaf[0] + straaf[1] + straaf[2]
				}
				if (straaf.length == 4) {
					this.xxlineaf = straaf[0] + straaf[1] + straaf[2] + straaf[3]
				}
				console.log('流速系数8转换', this.xxlineaf);

				// 修改流速系数9
				let laag = this.lineag * 10000
				let liaag = laag.toFixed(0) * 1
				let straag = liaag.toString(16).split('')
				if (straag.length == 1) {
					this.xxlineag = '0' + '0' + '0' + straag[0]
				}
				if (straag.length == 2) {
					this.xxlineag = '0' + '0' + straag[0] + straag[1]
				}
				if (straag.length == 3) {
					this.xxlineag = '0' + straag[0] + straag[1] + straag[2]
				}
				if (straag.length == 4) {
					this.xxlineag = straag[0] + straag[1] + straag[2] + straag[3]
				}
				console.log('流速系数9转换', this.xxlineag);

				// 修改流速系数10
				let laah = this.lineah * 10000
				let liaah = laah.toFixed(0) * 1
				let straah = liaah.toString(16).split('')
				if (straah.length == 1) {
					this.xxlineah = '0' + '0' + '0' + straah[0]
				}
				if (straah.length == 2) {
					this.xxlineah = '0' + '0' + straah[0] + straah[1]
				}
				if (straah.length == 3) {
					this.xxlineah = '0' + straah[0] + straah[1] + straah[2]
				}
				if (straah.length == 4) {
					this.xxlineah = straah[0] + straah[1] + straah[2] + straah[3]
				}
				console.log('流速系数10转换', this.xxlineah);

				// 修改流速系数11
				let laai = this.lineai * 10000
				let liaai = laai.toFixed(0) * 1
				let straai = liaai.toString(16).split('')
				if (straai.length == 1) {
					this.xxlineai = '0' + '0' + '0' + straai[0]
				}
				if (straai.length == 2) {
					this.xxlineai = '0' + '0' + straai[0] + straai[1]
				}
				if (straai.length == 3) {
					this.xxlineai = '0' + straai[0] + straai[1] + straai[2]
				}
				if (straai.length == 4) {
					this.xxlineai = straai[0] + straai[1] + straai[2] + straai[3]
				}
				console.log('流速系数11转换', this.xxlineai);

				// 修改左线系数
				let laj = this.linej * 10000
				let liaj = laj.toFixed(0) * 1
				let straj = liaj.toString(16).split('')
				if (straj.length == 1) {
					this.xxlinej = '0' + '0' + '0' + straj[0]
				}
				if (straj.length == 2) {
					this.xxlinej = '0' + '0' + straj[0] + straj[1]
				}
				if (straj.length == 3) {
					this.xxlinej = '0' + straj[0] + straj[1] + straj[2]
				}
				if (straj.length == 4) {
					this.xxlinej = straj[0] + straj[1] + straj[2] + straj[3]
				}
				console.log('左线系数转换', this.xxlinej);

				// 修改右线系数
				let lak = this.linek * 10000
				let liak = lak.toFixed(0) * 1
				let strak = liak.toString(16).split('')
				if (strak.length == 1) {
					this.xxlinek = '0' + '0' + '0' + strak[0]
				}
				if (strak.length == 2) {
					this.xxlinek = '0' + '0' + strak[0] + strak[1]
				}
				if (strak.length == 3) {
					this.xxlinek = '0' + strak[0] + strak[1] + strak[2]
				}
				if (strak.length == 4) {
					this.xxlinek = strak[0] + strak[1] + strak[2] + strak[3]
				}
				console.log('右线系数转换', this.xxlinek);

				// 修改流量系数
				let lal = this.linel * 10000
				let lial = lal.toFixed(0) * 1
				let stral = lial.toString(16).split('')
				if (stral.length == 1) {
					this.xxlinel = '0' + '0' + '0' + stral[0]
				}
				if (stral.length == 2) {
					this.xxlinel = '0' + '0' + stral[0] + stral[1]
				}
				if (stral.length == 3) {
					this.xxlinel = '0' + stral[0] + stral[1] + stral[2]
				}
				if (stral.length == 4) {
					this.xxlinel = stral[0] + stral[1] + stral[2] + stral[3]
				}
				console.log('流量系数转换', this.xxlinel);

				// 修改测站类型
				let laaj = this.radio2 * 1
				let liaaj = laaj.toFixed(0) * 1
				let straaj = liaaj.toString(16).split('')
				if (straaj.length == 1) {
					this.xxlineaj = straaj[0] + '0' + '0' + '0'
				}
				if (straaj.length == 2) {
					this.xxlineaj = straaj[0] + straaj[1] + '0' + '0'
				}
				if (straaj.length == 3) {
					this.xxlineaj = straaj[0] + straaj[1] + straaj[2] + '0'
				}
				if (straaj.length == 4) {
					this.xxlineaj = straaj[0] + straaj[1] + straaj[2] + straaj[3]
				}
				console.log('测站类型转换', typeof this.xxlineaj);
				// this.resHexitem  nubsfg iditem
				console.log('型号',typeof this.nubsfg ,typeof this.resHexitem );

				this.jis = this.resHexitem + '10' + this.nubsfg + this.modifynum + '00' + '28' + '50' + '00' + '00' + this.xxlinea + this
					.xxlineh + this.xxlinei + this.xxlinee + this.xxlinef + this.xxlineg + this.xxlineb + this.xxlinec +
					this.xxlined + this.xxlineradio1 + this.xxlinem + this.xxlinen + this.xxlineo + this.xxlinep + this
					.xxlineq + this.xxliner + this.xxlines + this.xxlinet + this.xxlineu + this.xxlinev + this.xxlinew +
					this.xxlinex + this.xxliney + this.xxlinez + this.xxlineaa + this.xxlineab + this.xxlineac + this
					.xxlinead + this.xxlineae + this.xxlineaf + this.xxlineag + this.xxlineah + this.xxlineai + this
					.xxlinej + this.xxlinek + this.xxlinel + this.xxlineaj + '00' + '00'
console.log('计算1', this.jis);
				this.crc16up(this.jis)
				
				console.log('计算2', this.jis,this.jis.length);
				console.log('CRC', this.cr);
				let n = 2;
				for (var i = 0, l = this.jis.length; i < l / n; i++) {
					var a = this.jis.slice(n * i, n * (i + 1));
					this.countall.push(a);
				}
				console.log('阶梯', this.countall);
				
				let counmap = []
				counmap.length = 0
				counmap = this.countall.map((item)=>{
					return '0x' + item
				})
				counmap.push('0x' + this.cr[0])
				counmap.push('0x' + this.cr[1])
				console.log('转换阶梯',counmap);
				setTimeout(() => {
					if (this.countall[0] !== '') {
						const buffer = new ArrayBuffer(89)
						const dataView = new DataView(buffer)
						for (var i = 0; i < counmap.length; i++) {
							dataView.setUint8(i, counmap[i])
						}
						this.sendMsgToKey(buffer)
						uni.showLoading({
							title: '修改中...'
						});
						setTimeout(() => {
							uni.hideLoading()
						}, 4000)
					}
				}, 500)
			},
			// 分包
			/**
			 * 向设备发送消息(分包发送，单包20字节，递归发送)
			 */
			sendMsgToKey(buffer) {
				var that = this //vue中的this
				const packageSize = 1 //分包大小
				if (buffer.byteLength <= 1) { //如果小于20直接发送，不再继续调用
					uni.writeBLECharacteristicValue({
						// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
						deviceId: that.deviceId,
						// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
						serviceId: that.serviceId,
						// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
						characteristicId: that.fff, //第二步写入的特征值
						// 这里的value是ArrayBuffer类型
						value: buffer,
						writeType: 'write',
						success: (res) => {
							//此时设备已接收到你写入的数据
							console.log('写入一');
							// setTimeout(() => {
							// 	console.log('循环');
							// 	if (this.fanti) {
							// 		this.modifyup()
							// 	}
							// }, 500)
							console.log('this.fanti', this.fanti);

						},
						fail: (err) => {
							if (err.errCode == 10006) {
								uni.hideLoading()
								uni.showToast({
									title: '当前连接已断开',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
							if (err.errCode == 10004) {
								uni.hideLoading()
								uni.showToast({
									title: '未找到服务',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
							if (err.errCode == 10005) {
								uni.hideLoading()
								uni.showToast({
									title: '未找到特征值',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
							console.log('99999', err)
						},
						complete: function() {}
					})
				} else { //如果大于20发送完成后继续递归调用
					var newData = buffer.slice(1)
					var writeBuffer = buffer.slice(0, 1)
					uni.writeBLECharacteristicValue({
						// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
						deviceId: that.deviceId,
						// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
						serviceId: that.serviceId,
						// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
						characteristicId: that.fff, //第二步写入的特征值
						// 这里的value是ArrayBuffer类型
						value: writeBuffer,
						writeType: 'write',
						success: function(res) {
							//写入成功后继续递归调用发送剩下的数据
							that.sendMsgToKey(newData)
							console.log('递归写入');
						},
						fail: (err) => {
							console.log('88888', err)
							if (err.errCode == 10006) {
								uni.hideLoading()
								uni.showToast({
									title: '当前连接已断开',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
							if (err.errCode == 10004) {
								uni.hideLoading()
								uni.showToast({
									title: '未找到服务',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
							if (err.errCode == 10005) {
								uni.hideLoading()
								uni.showToast({
									title: '未找到特征值',
									icon: 'success',
									mask: true,
									duration: 2000
								});
							}
						},
						complete: function() {}
					})
				}

			},
		}
	}
</script>
<style>
	page {
		background-color: #f8f8f8;
	}
</style>
<style scoped lang="scss">
	.hometop {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		font-weight: bold;
		text-align: center;
		color: #43b998;
		padding: 2rpx 0 0 0;
		border-radius: 10rpx;
	}

	.abr {
		display: flex;
		justify-content: space-between;
		padding: 30rpx;

		.abr-l {
			width: 710rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;

			.hometop {
				width: 450rpx;
				height: 80rpx;
				line-height: 80rpx;
				background-color: #e4f4f0;
			}

			.abrlist {
				.abritem {
					font-size: 25rpx;
					display: flex;
					align-items: center;
					margin: 10rpx;

					.abrtext {
						width: 200rpx;
					}

					.abrinput {
						width: 350rpx;
					}
				}
			}
		}


	}

	.abr-r {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;

		.mini-btn {
			margin: 20rpx;

		}
	}

	.formula {
		width: 750rpx;
		margin-top: 40rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.formulatop {
			width: 600rpx;
			text-align: center;
			line-height: 80rpx;
			font-size: 30rpx;
			border-radius: 15rpx 15rpx 0 0;
			background-color: #327983;
			color: #ffffff;
		}

		.formulabom {
			width: 600rpx;
			height: 200rpx;
			text-align: center;
			line-height: 70rpx;
			font-size: 30rpx;
			border-radius: 0 0 15rpx 15rpx;
			background-color: #b0ddd4;
			color: #ffffff;
			display: flex;
			flex-wrap: wrap;
			align-content: space-around;
			justify-content: space-around;

			.formulaitem {
				width: 250rpx;
				height: 70rpx;
				margin: 0rpx;
				line-height: 70rpx;
				border-radius: 10rpx;
				background-color: #ffffff;
				color: #327983;
			}
		}
	}

	.bott {
		height: 200rpx;
		text-align: center;
	}

	.abrcheckbox {
		height: 200rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}
</style>